package com.newly.api.sys.feign;

import com.newly.common.base.constants.ServerUriConstant;
import com.newly.common.base.entity.R;
import com.newly.common.base.entity.sys.dict.dto.CreateDictDto;
import com.newly.common.base.entity.sys.dict.dto.DictTypeDto;
import com.newly.common.base.entity.sys.dict.dto.UpdDictDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author gjm guan
 * @date 2021/11/9 16:01
 * @desc 字典表接口
 */
@Api(tags = "字典表接口")
@FeignClient(path = ServerUriConstant.NEWLY_SYS_DICT, name = ServerUriConstant.NEWLY_SYS_SERVICE_NAME)
public interface DictClient {

    /**
     * 导出参数配置表
     * @param keyword
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation("导出参数配置表")
    @GetMapping("/export")
    void exportDict(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "startTime", required = false) String startTime,
            @RequestParam(value = "endTime", required = false) String endTime,
            HttpServletResponse response
    );

    /**
     * 参数键名查重
     * @param code
     * @return
     */
    @ApiOperation("参数键名查重")
    @GetMapping("/keyDuplicate")
    R keyDuplicate(String code);

    /**
     * 根据id获取字典信息
     * @param id
     * @return
     */
    @GetMapping("/queryDictById")
    R queryDictById(Integer id);

    @ApiOperation("查询字典创建人")
    @GetMapping("/queryTenantOfCreateDict")
    R queryTenantOfCreateDict();

    @ApiOperation("创建字典")
    @PostMapping("/createDict")
    R createDict( @RequestBody CreateDictDto dictDto);

    @ApiOperation("通过id删除字典")
    @ApiImplicitParam(name = "dictIds", value = "字典id", allowMultiple = true, dataType = "string", paramType = "query")
    @PostMapping("/removeDictByIds")
    R removeDict(@RequestBody List<String> dictIds);

    @ApiOperation("查询字典列表")
    @GetMapping("/listDict")
    R listDict(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "offset", required = false) Integer offset,
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "startTime", required = false) String startTime,
            @RequestParam(value = "endTime", required = false) String endTime
    );

    @ApiOperation("修改字典")
    @PostMapping("/modifyDict")
    R modifyDict(@RequestBody UpdDictDto dictDto);

    @ApiOperation("查询字典类型列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "offset", value = "页码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "页数", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "创建开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "创建结束时间", dataType = "string", paramType = "query"),
    })

    @GetMapping("/listDictType")
    R listDictType(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "offset", required = false) Integer offset,
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "startTime", required = false) String startTime,
            @RequestParam(value = "endTime", required = false) String endTime
    );

    @ApiOperation("查询字典类型")
    @GetMapping("/queryDictType")
    R queryDictType();

    @ApiOperation("通过id删除字典类型")
    @ApiImplicitParam(name = "dictTypeIds", value = "字典id", allowMultiple = true, dataType = "string", paramType = "query")
    @PostMapping("/removeDictTypeByIds")
    R removeDictType(@RequestParam("dictTypeIds") List<String> dictTypeIds);

    @ApiOperation("创建字典类型")
    @PostMapping("/createDictType")
    R createDictType(@RequestBody DictTypeDto dictTypeDto);

    @ApiOperation("修改字典类型")
    @PostMapping("/modifyDictType")
    R modifyDictType(@RequestBody DictTypeDto dictTypeDto);

    @ApiOperation("刷新redis字典数据缓存")
    @PostMapping("/refreshCache")
    R refreshCache();
}
